﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;

namespace FarmacieDAL
{
    public partial class Medicament
    {
        private const int DecemberMonthValue = 12;

        public static List<Substanta_Activa> ToateSubstantele
        {
            get { return SubstanteActiveManager.ToateSubstantele; }
        }

        public static List<Producator> TotiProducatorii
        {
            get { return ProducatoriManager.TotiProducatorii; }
        }

        public static List<Unitate_Masura> ToateUnitatile
        {
            get { return UMManager.ToateUnitatile; }
        }

        public double StocCritic
        {
            get
            {
                var stocCritic = StocCriticManager.ToateStocurileCritice.FirstOrDefault(x => x.Id_Medicament == this.Id_Medicament);
                return stocCritic != null ? stocCritic.Cantitate : 0;
            }
        }

        public double CantitateInStoc
        {
            get
            {
                var stocuri = FarmacieDALManager.EntitiesContext.Stoc.Where(x => x.Id_Medicament == this.Id_Medicament && x.Data_Intrare <= DateTime.Now && x.Data_Expirare > DateTime.Now);
                return stocuri.Count() > 0 ? stocuri.Sum(x => x.Cantitate_Actuala) : 0;
            }
        }

        public double CantitateRecomandata
        {
            get
            {
                return (double)FarmacieDALManager.EntitiesContext.CalculeazaStocLunar(this.Id_Medicament, DateTime.Now.AddMonths(1).Month).First().Value;
            }
        }

    }
}
